<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>陕西人才发展知识库系统登录</title>
<script type="text/javascript"
	src="../../bootstrap-3.3.7/dist/js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/login/jquery.form.min.js"></script>
<link href="../../css/login/login.css" rel="stylesheet" type="text/css" />

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link
	href="../../bootstrap-3.3.7/docs/assets/css/ie10-viewport-bug-workaround.css"
	rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
<script type="text/javascript" src="../../js/jquery.base64.js"></script>
</head>
<body onLoad="createCode()">
	<div class="login">
		<div class="login-head">
			<div class="login-head-a">
				<img src="../../image/login/a.jpg" style="margin-top: 12px" title=""
					alt="" />
			</div>
			<div class="login-head-b" style="width: 400px">陕西人才发展知识库系统</div>
		</div>
		<div class="login-con">
			<div class="login-a">
				<form id="loginForm" method="post">
					<div class="login-b">
						<div class="login-b-a">用户登录</div>
						<div class="login-b-b">
							<ul>
								<li><label for="user_id">手机号：</label><input type="text"
									id="user_id" name="user_id" placeholder="手机号" />
									<h1 id="m-tip"></h1></li>
								<li><label for="user_password">密 &nbsp;&nbsp;码：</label><input
									type="password" id="user_password" name="user_password" />
									<h1 id="p-tip"></h1></li>
								<li><label>验证码：</label><input type="text" id="input1" /> <input
									type="text" id="checkCode" class="code" style="width: 55px"
									readonly="true" /> <a href="#" onClick="createCode()">看不清楚</a>
									<h1 id="c-tip"></h1></li>
								<li style="height: 25px;"><input
									style="height: 20px; width: 20px; float: left; margin: 0; padding: 0;"
									name="remember-me" id="remember-me" type="checkbox" value="" />&nbsp;&nbsp;记住我
									
								<li class="login-x" style="height: 20px; margin: 0">
									<div class="login-x-a">
										<input id="logbutton" type="button" value="登录"
											onclick="submitForm()" />
										<div class="x"></div>
									</div>
									<div class="login-x-a">
										<input type="button" value="注册" onclick="register()" />
										<div class="x"></div>
									</div>
								</li>
							</ul>
						</div>
						<div class="login-b-c">
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="changepassword.jsp">忘记登录密码？</a>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div class="login-foot">版权所有：陕西创新人才发展研究院</div>
	</div>
	<script type="text/javascript">
		var code; //在全局 定义验证码  

		$(function() {

			if ($.cookie('bit') == 'true') {
				var password = $.cookie('user_password');
				$('#remember-me').attr('checked', 'checked');
				$('#user_id').val($.cookie('user_id'));
				$('#user_password').val($.base64.decode(password));
			}
		});
		$("body").keydown(function() {
			if (event.keyCode == "13") {//keyCode=13是回车键
				$("#logbutton").click();
			}
		});
		function createCode() {
			code = "";
			var codeLength = 4;//验证码的长度      
			var checkCode = document.getElementById("checkCode");
			checkCode.value = "";
			var selectChar = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b',
					'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p',
					'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
					'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P',
					'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');

			for (var i = 0; i < codeLength; i++) {
				var charIndex = Math.floor(Math.random() * 60);
				code += selectChar[charIndex];
			}
			if (code.length != codeLength) {
				createCode();
			}
			checkCode.value = code;
		}

		function validate() {
			var mobile = $("#user_id").val();
			var password = $("#user_password").val();
			var checkCode = $("#input1").val();
			if (mobile == "" || mobile == null || mobile == "手机号") {
				$("#m-tip").html("请输入手机号");
				return false;
			}
			$("#m-tip").html("");
			if (password == "" || password == null) {
				//alert("输入正确，输入的验证码为："+inputCode);
				$("#p-tip").html("请输入密码！")
				return false;
			}
			$("#p-tip").html("")
		}

		function submitForm() {
			validate();
			var inputCode = document.getElementById("input1").value
					.toUpperCase();
			var codeToUp = code.toUpperCase();
			if (inputCode.length <= 0) {
				$("#c-tip").html("请输入验证码！");
				return false;
			} else if (inputCode != codeToUp) {
				$("#c-tip").html("验证码输入错误！");
				createCode();
				return false;
			}
			$("#c-tip").html("");
			$("#loginForm").ajaxSubmit({
				url : "../permission/getUserLogin",
				success : function(result) {
					if (result == 1) {
						if ($('#remember-me').is(':checked')) {
							$.cookie('user_id', $("#user_id").val(), {
								expires : 7
							});
							$.cookie('user_password', $.base64.encode($("#user_password").val()), {
								expires : 7
							});
							$.cookie('bit', 'true', {
								expires : 7
							});
						} else {
							$.removeCookie('user_id');
							$.removeCookie('user_password');
							$.removeCookie('bit');
						}
						window.location = "../information/getInformation";
					} else {
						createCode();
						$("#c-tip").html("用户名或者密码输入错误！");
					}
				}
			});
		}
		function register() {
			window.location.href = "register.jsp"
		}
	</script>
</body>
</html>
